<title>Stemmer Indonesia</title>
<link href="tema/tema.css" rel="stylesheet" type="text/css" />

<!-- Tema Untuk font -->
<style type="text/css">
.temaFont {
	font-size: 13px;
	color: #003366;
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-weight: bold;
	text-decoration: none;
	letter-spacing: 2pt;
}
table,th,td
{
border:1px solid black;
border-collapse:collapse;
}
th,td
{
padding:5px;
}
</style>

<!-- validasi data kosong -->
<script language=javascript>
function validasi(){
	if (document.forms[0].text.value==""){
		alert("Kalimat Masih Kosong ...")
		document.forms[0].text.focus();
		return false;
	}
}
</script>

<body background="gambar/bgtengah.jpg">
	<p align="center">&nbsp;</p>
	<p align="center"><span>
	</span></p>

	<!-- membuat form dengan metode post -->
	<form name="formBocahIlang" method="post" action="" onSubmit="return validasi()">
		<table width="400" border="0" align="center" cellspacing="1" bgcolor="lightsteelblue">
			<tr valign="middle">
				<td height="21" align="left" bgcolor="#FFFFFF" colspan="2">&nbsp;Stemming ... </td>
			</tr>

			<tr valign="middle">
				<td width="200" background="gambar/bgtr.gif" bgcolor="#FFFFFF" height="21" align="left">&nbsp;</td>
				<td background="gambar/bgtr.gif" bgcolor="#FFFFFF" height="21" align="left">&nbsp;Teks</td>
			</tr>

			<tr valign="middle" bgcolor="#FAFAFA">
				<td height="21" align="left">&nbsp;Kata / &nbsp;Kalimat:</td>
				<td height="21" align="left">
					<textarea name="text" cols="50" rows="5"></textarea></td>
				</tr>

				<tr valign="middle" bgcolor="#FAFAFA">
					<td height="21" align="left">&nbsp;&nbsp;</td>
					<td height="21" align="left">
						<input type="submit" value="Proses" style=" border: 1px solid #666666; background-color:#EEEEEE;"/>
						&nbsp;
						<input type="reset" value="Ulangi" style=" border: 1px solid #666666; background-color:#EEEEEE;"/>
					</td>
				</tr>
			</table>
			<p><table width="400" border="0" bgcolor="LightSteelBlue" cellspacing="1" align="center" cellpadding="5">
				<br>
				<!-- Judul Atas -->
				<tr>
					<td width="407" background="gambar/bgtr.gif" bgcolor="#EBEBEB">&nbsp;&nbsp;<a>Hasil Stemming ...</a></td>
				</tr>
				<tr>
					<td bgcolor="#FAFAFA"><br>
						<?php
						include("kelas/koneksi.php");
						include ('kelas/proses.php');
						include ('kelas/stopwords.php');
						$kon = new database;
						$kon->database();

						if (!empty($_POST['text'])){
							$teks = strtolower($_POST['text']);

							$tokenKarakter=array(PHP_EOL,'','',' ','/',',','?','.',':',';',',','!','[',']','{','}','(',')','-','_','+','=','<','>','\'','"','\\','@','#','$','%','^','&','*','`','~','0','1','2','3','4','5','6','7','8','9','â','','');
							$teks= str_replace($tokenKarakter,' ',$teks);
							$tok = strtok($teks, "\n\t");

							while ($tok !== false) {
								$teks = $tok;
								$tok = strtok(" \n\t");
							}

							$split = explode(' ',$teks);
							echo 'sebelum remove stopwords : <br>'.$teks."<br><br> sesudah remove stopwords : <br>";
							$kalimat = array();
							foreach($split as $key=>$kata){
								$kata = stopwords(trim($kata));
								array_push($kalimat, trim($kata));
								echo $kata;
							}
							echo '<br><br>Stemming : <br>';
							$kal = array_filter($kalimat);
							//print_r($kal);
							$kata_stem = array();
							$no = 1;
							foreach ($kal as $k => $value) {
								$stem = proses(trim($value));
								echo $no++.") ".$value."=>".$stem."<br>";
								array_push($kata_stem, trim($stem));
							}
							echo " <br>kalimat yang udah di stemming dan remove stopwords : <br>";
							$kalimat_after = implode(' ', $kata_stem);
							print_r($kalimat_after);
							echo "<br><br>jumlah kata : ".count($kata_stem);

							?>
					</td>
				</tr>
			</table>
			<br/><br />
			<center>
				<h3>Hasil Perbandingan dengan Database</h3>	
			<table>
				<tr>
					<th>Dokumen Ke-</th>
					<th>jumlah kata Dokumen Lama</th>
					<th>jumlah kata sama</th>
					<th>jumlah kata berbeda</th>
					<th>persentase</th>
				<tr>
				<?php

							//lakukan insert hanya jika diterima
							// $sqlinsert = "insert into tesis values ('$kalimat_after')";
							// mysql_query($sqlinsert);
							$sql = "select stem_thesis from tesis";
							$result = mysql_query($sql);
							
							$num=1;
							while ($resultarray = mysql_fetch_assoc($result)) {
							$kalimat_lama = explode(' ', $resultarray['stem_thesis']);
								$difference = array_diff($kata_stem, $kalimat_lama);
								//print_r($difference);
								$intersect = array_intersect($kata_stem, $kalimat_lama);
								echo "<tr>";
								echo "<td>".$num++."</td>";
								echo "<td>".count($kalimat_lama)."</td>";
								echo "<td>".count($intersect)."</td>";
								echo "<td>".count($difference)."</td>";
								echo "<td>".((count($intersect)/count($kata_stem))*100)."</td>";
							}
						}
						?>
				</table>
			</center>
		</p>
	</form>
	<p>
	</body>
	<div align="center"><a href="./"></a></div>